<template>
	<view class="chat-item">
		<view class="chat-time" v-if="item.date">{{item.date}}</view>
		<view class="chat-list d-flex jc-start" :class="{'chat-me': item.isme}">
			<image class="avatar" v-if="!item.isme" :src="item.userpic" mode="widthFix" lazy-load></image>
			<view class="char-list-body">
				<!-- 文字 -->
				<text v-if="item.type === 'text'">{{item.data}}</text>
				<!-- 图片 -->
				<image v-if="item.type === 'img'" class="message-pic" :src="item.data" mode="widthFix" lazy-load></image>
			</view>
			<image v-if="item.isme" class="avatar" :src="item.userpic" mode="widthFix" lazy-load></image>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			item: {
				type: Object
			},
			index: {
				type: Number
			}
		}
	}
</script>

<style lang="scss" scoped>
	.chat-item {
		.chat-time {
			text-align: center;
			padding: 30upx 0;
			font-size: 28upx;
			color: #c2c2c2;
		}

		.chat-list {
			padding: 18upx 0;

			.avatar {
				width: 100upx;
				height: 100upx;
				margin-left: 25upx;
				border-radius: 12upx;
				flex-shrink: 0;
			}

			.char-list-body {
				.message-pic {
					max-width: 200upx;
					max-height: 400upx;
				}

				position: relative;
				background-color: #dddddd;
				padding: 25upx;
				margin-left: 20upx;
				border-radius: 20upx;
				margin-right: 100upx;
				max-width: 400upx;
				word-break:break-all;
			}

			.char-list-body:after {
				content: "";
				position: absolute;
				top: 30upx;
				left: -30upx;
				right: 0;
				width: 0;
				height: 0;
				border: 16upx solid #dddddd;
				border-color: transparent #DDDDDD transparent transparent;
			}
		}

		.chat-me {
			justify-content: flex-end;

			.avatar {
				margin-right: 25upx;
			}

			.char-list-body {
				margin-right: 0;
			}

			.char-list-body:after {
				left: auto;
				right: -30upx;
				border-color: transparent transparent transparent #DDDDDD;
			}
		}
	}
</style>
